//
//  WKOneViewController.m
//  WKDemo
//
//  Created by wangzhaohui-Mac on 14-7-31.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKOneViewController.h"
#import "WKOneEliteViewController.h"
#import "WKOneNewViewController.h"
#import "WKOneThroughViewController.h"
#import "WKNavigationController.h"

#define WKChildViewX 0
#define WKChildViewY 0
#define WKChildViewW 320
#define WKChildViewH 372

@interface WKOneViewController ()
#warning 保存子控制器不被销毁
@property (nonatomic,strong) WKOneEliteViewController *eliteVC;
@property (nonatomic,strong) WKOneNewViewController *NewVC;
@property (nonatomic,strong) WKOneThroughViewController *throughVC;
@end

@implementation WKOneViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    //添加子视图
    [self addSubView];
    
}

#pragma mark - 刷新
- (void)refresh:(BOOL)fromSelf
{
    
//    if (self.tabBarItem.badgeValue) {
//        
//        //刷新数据
//        [self.eliteVC.tableView footerBeginRefreshing];
//    }else
    if (fromSelf)
    {
        //刷新数据
        [self.eliteVC.tableView footerBeginRefreshing];
        //让tableView的cell回到顶部
        NSIndexPath *firstRow = [NSIndexPath indexPathForRow:0 inSection:0];
        [self.eliteVC.tableView scrollToRowAtIndexPath:firstRow atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}

/**
 *  刷新
 */
- (void)rightRefresh:(UIBarButtonItem *)btn
{
    if (self.selectedBtnOne.selected) {
        //当刷新按钮被点击的时候就发出通知
        [[NSNotificationCenter defaultCenter] postNotificationName:WKDidDeletedNotificationOne object:nil userInfo:nil];
    }else if (self.selectedBtnTwo.selected)
    {
        //当刷新按钮被点击的时候就发出通知
        [[NSNotificationCenter defaultCenter] postNotificationName:WKDidDeletedNotificationTwo object:nil userInfo:nil];
        
    }else
    {
        //当刷新按钮被点击的时候就发出通知
        [[NSNotificationCenter defaultCenter] postNotificationName:WKDidDeletedNotificationThree object:nil userInfo:nil];
    }
    
    
}
/**
 添加子视图
 */
- (void)addSubView
{
    //精华
    WKOneEliteViewController *eliteVC = [[WKOneEliteViewController alloc] init];
    //设置导航控制器
    eliteVC.naVc = self.navigationController;
    self.eliteVC = eliteVC;
    
    eliteVC.tableView.frame = CGRectMake(WKChildViewX, WKChildViewY, WKChildViewW, WKChildViewH);

//    self.eliteTableView = eliteVC.tableView;
    [self.scrollView addSubview:eliteVC.tableView];
    
    //最新
    WKOneNewViewController *newVC = [[WKOneNewViewController alloc] init];
    newVC.naVc = self.navigationController;
    self.NewVC = newVC;
    newVC.tableView.frame = CGRectMake(WKChildViewX + WKScreenW, WKChildViewY, WKChildViewW, WKChildViewH);

//    self.newtableView = newVC.tableView;
    [self.scrollView addSubview:newVC.tableView];
    
    //穿越
    WKOneThroughViewController *throughVC = [[WKOneThroughViewController alloc] init];
    throughVC.naVc = self.navigationController;
    self.throughVC = throughVC;
    throughVC.tableView.frame = CGRectMake(WKChildViewX + 2*WKScreenW,WKChildViewY, WKChildViewW, WKChildViewH);

//    self.throughTableView = throughVC.tableView;
    [self.scrollView addSubview:throughVC.tableView];
        
}

@end
